home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8802 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: on OO differnces between Ada95 and C++
  5. Date: 26 Feb 1996 19:57:04 GMT
  6. Organization: Borland International
  7. Message-ID: <4gt3ag$76m@druid.borland.com>
  8. References: <4gbq7q$g08@qualcomm.com> <3129F185.41C6@Rational.COM> <4gi413$qo1@druid.borland.com> <4gspen$ot0@hacgate2.hac.com>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4gspen$ot0@hacgate2.hac.com>, ddavenpo@redwood.hac.com says...
  15. >
  16. >Pete Becker (pete@borland.com) wrote:
  17. >: In article <3129F185.41C6@Rational.COM>, jDesquilbet@Rational.COM says...
  18. >: >
  19. >: >- you may have several different definitions for the same class in the
  20. >: >same program, as long as they are never compiled together in the same
  21. >: >compilation unit; example:
  22. >: >
  23. >: >#define private public // *** BERK! ***
  24. >: >#include "...h"        // second definition for the same class
  25. >: >#undef private
  26. >
  27. >: This is not true. A program that attempts to do this violates the one 
  28. >: definition rule, so it is not a legal C++ program.
  29. >:       -- Pete
  30. >
  31. >We need to be careful here with terms used to describe C++ constructs.  
  32. >A class name declaration is a C++ declaration (ARM C++ 3.1) not a definition.
  33.  
  34. This is a red herring. The issue is not about a "class name declaration", but 
  35. about the actual definition of the class.
  36.  
  37. >This is what is specified in ".h" files.  There can be multiple declarations
  38. >so the above code is legal C++ code.  
  39.  
  40. There can be multiple declarations of the name, but that is irrelevant.
  41.  
  42. >There can only be one definition
  43. >of each object, function, class, and enumerator in a program and these
  44. >are specified in ".cc" files.  Mr. Becker is correct about stating that
  45. >there must be only one definition but that rule does not apply in this
  46. >instance.
  47.  
  48. No, my original statement is correct: a program which contains multiple 
  49. definitions of the same class is not a valid C++ program because it violates 
  50. the one definition rule. That is exactly the case that the original message 
  51. attempts to create, as indicated by the prefatory text which says "you may 
  52. have several different definitions for the same class in the same program, as 
  53. long as they are never compiled together in the same compilation unit" and by 
  54. the comment that says "second definition for the same class". You MAY NOT have 
  55. several definitions for the same class in the same program. Changing private 
  56. members to public creates a different definition of the class and is illegal. 
  57. Class definitions are not local to a compilation unit, and cannot be treated 
  58. so cavalierly. There aren't many compilers that enforce this rule, but it is 
  59. nevertheless a constraint on valid C++ programs.
  60.     -- Pete
  61.  
  62.